package com.hzjq.core.massage

import com.hzjq.core.util.Convert

class DataMessageBean : MessageBean {

    constructor(content: String) : super(content)

    override fun assembly(): ByteArray {
//        val mByte = Convert.hexString2Bytes(content)
//        if(mByte != null) {
//            val str = Convert.getSum8(mByte, mByte.size)
//            return Convert.hex2byte(str)
//        }
//        return Convert.hex2byte(content)
        val preContent = content.subSequence(4,content.length).toString()
        val mByte: ByteArray = Convert.hexStringToBytes(preContent.toUpperCase())
        if (mByte != null) {
            buf.delete(0,buf.length)
            val length = 3 + mByte.size
            val preCrc = buf.append("23").append(Convert.byteToHex2(length).toString()).append(preContent.toUpperCase()).toString()
            val preByte: ByteArray = Convert.hexStringToBytes(preCrc)
            val str = Convert.getSum8(preByte,preByte.size)
            return Convert.hexStringToBytes(str)
        }
        return content.toByteArray()
    }
}